package edu.ads.bookloan;
import java.util.Date;


public class LatestAvailableBookSingleton {
	
	public Book latestAvailableBook;
	public Date addDate;
	
	private static LatestAvailableBookSingleton instance = new LatestAvailableBookSingleton();
	
	private LatestAvailableBookSingleton(){}
	public static LatestAvailableBookSingleton getInstance(){
		return instance;
	}
	
	public synchronized Book getLatestAvailableBook(){
		if(addDate != null && (new Date().getTime() - addDate.getTime()) > 60*1000){
			latestAvailableBook = null;
			addDate = null;
		}
		return latestAvailableBook;
	}
	
	
	public synchronized void  setLatestAvailableBook(Book latestAvailableBook){
		this.latestAvailableBook = latestAvailableBook;
		addDate = new Date();
	}
	
}
